from aiogram_dialog import DialogManager
from sqlalchemy.ext.asyncio import AsyncSession

from app.bot.services.locale import Locale
from app.database.services.categories import query_categories


async def categories_getter(
    db_session: AsyncSession, dialog_manager: DialogManager, **kwargs
):

    proxy_type: str = dialog_manager.dialog_data.get("proxy_type")
    proxy_privacy: str = dialog_manager.dialog_data.get("proxy_privacy")
    provider_id: int = dialog_manager.dialog_data.get("provider_id")
    country_id: int = dialog_manager.dialog_data.get("country_id")

    locale: Locale = dialog_manager.middleware_data.get("locale")

    if locale.translators[0].locale == "en":
        user_language = "en"
    else:
        user_language = "ru"

    categories = await query_categories(
        db_session, proxy_type, proxy_privacy, country_id, provider_id
    )

    return {
        "categories": categories,
        "count": len(categories),
        "user_language": user_language,
    }
